home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / interp18.lha / interp-1.8 / Symbol.h < prev    next >
C/C++ Source or Header  |  1990-01-22  |  4KB  |  130 lines

  1. // -*- C++ -*- Symbol.h -- the Class declaration for the class Symbol.
  2. // Copyright (C) 1989 Carey Richard Murphey.
  3. // (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 1, or (at your option)
  8. // any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef _Symbol_h_
  20. #pragma once
  21. #define _Symbol_h_ 1
  22. #include <String.h>
  23. #include "Table.defs.h"
  24.  
  25. typedef double (t_func)(double arg); // pointer to function returning double.
  26.  
  27. class Symbol            // a generic symbol.
  28. {
  29. protected:
  30.   union {
  31.     double * double_p;        /* pointer to a floating point variable */
  32.     int    * int_p;        /* pointer to an integer variable */
  33.     t_func * t_func_p;        /* pointer to a function */
  34.   } v;                /* change this to an unnamed union later */
  35. public:
  36.   Symbol () {}
  37.   virtual int type () = 0;    // every subclass must define it's type.
  38.   virtual ostream& echo (ostream& Stream) = 0; // and echo itself.
  39.   virtual void assign (double p);
  40.   virtual void assign (int    p);
  41.   virtual operator double ();
  42.   virtual operator int    ();
  43.   virtual double func (double p);
  44.   friend ostream& operator << (ostream& Stream, Symbol* p);
  45. };
  46.  
  47. // a user defined or builtin double precision number.
  48. class Double_Pointer : public Symbol
  49. {
  50. public:
  51.   Double_Pointer (double p)
  52.     : Symbol () {v.double_p = new double; *v.double_p = p;}
  53.   Double_Pointer (double* p)
  54.     : Symbol () {v.double_p = p;}
  55.   virtual void assign (double p);
  56.   virtual void assign (int    p);
  57.   operator double ();
  58.   operator int ()   ;
  59.   int type ();
  60.   ostream& echo (ostream& Stream);
  61. };
  62.  
  63.  
  64. // a user defined or builtin integer number.
  65. class Int_Pointer : public Symbol
  66. {
  67. public:
  68.   Int_Pointer (int p) : Symbol () {v.int_p = new int; *v.int_p = p;}
  69.   Int_Pointer (int* p) : Symbol () {v.int_p = p;}
  70.   virtual void assign (double p);
  71.   virtual void assign (int    p);
  72.   operator double ();
  73.   operator int    ();
  74.   int type ();
  75.   ostream& echo (ostream& Stream);
  76. };
  77.  
  78. // a builtin double precision function.
  79. class Function : public Symbol
  80. {
  81. public:
  82.   Function (t_func *p) : Symbol () {v.t_func_p = p;}
  83.   double func (double p);
  84.   int type ();
  85.   ostream& echo (ostream& Stream);
  86.   void assign (void * p);
  87. };
  88.  
  89. // a user defined integer function.
  90. class Int_Function : public Symbol
  91. {
  92. protected:
  93.   Node *ast;            // pointer to the tree holding the function.
  94.   StringXPlex *arglist;        // an odered list of argument names.
  95.   StringXPlex *locals;        // an odered list of local variable names.
  96. public:
  97.   Int_Function (Node *p) : Symbol () {ast = p;}
  98.   double func (double p);
  99.   int type ();
  100.   ostream& echo (ostream& Stream);
  101.   void assign (void * p);
  102. };
  103.  
  104. // a user defined double precision function.
  105. class Double_Function : public Symbol
  106. {
  107. protected:
  108.   Node *ast;            // pointer to the tree holding the function.
  109.   Table symtab;            // the local symbol table holding the arguemnts.
  110.   String *arglist;        // an array of arguemnt names.
  111. public:
  112.   Double_Function (t_func *p) : Symbol () {v.t_func_p = p;}
  113.   double func (double p);
  114.   int type ();
  115.   ostream& echo (ostream& Stream);
  116.   void assign (void * p);
  117. };
  118.  
  119. typedef Symbol * Symbolp;
  120.  
  121. #if defined(__OPTIMIZE__) && !defined(INLINE)
  122. #define INLINE inline
  123. #include "Symbol.cc"
  124. #ifdef INLINE
  125. #undef INLINE
  126. #endif
  127. #endif
  128.  
  129. #endif
  130.